<?php
    require_once(MODEL_PATH.'/CMS/Base.php');
    class Model_CMS_Product extends MODEL_CMS_Base{
        
        function __construct(){
        }
        
        function basic_info($product_id){
          $dbh_r = $this->db_connect('read');
          $h_product = db_selectrow_hash($dbh_r, 'select * from product where id=?', $product_id);

		  return $h_product;
        }
        
     
        function single_photo($photo){
        	$image2='';
        	$size1='';
        	$size2='';
        	
        	if ($photo == ''){
        		return 'No Photo';
        	}
        	
        	
        	$html  = '<script type="text/javascript">';
        	$html .= "CMS.image_uplaod.show('$photo','$image2',";
        	$html .= "'$size1','$size2'); </script>";
        	return $html;
        }    
        
    function detail_html($product_id){
    	 $dbh_r = $this->db_connect('read');
       $h_product = db_selectrow_hash($dbh_r, 'select * from product where id=?', $product_id);
 
       $brand_name = db_select_one($dbh_r, 'select name from brand where id=? and status=1', $h_product['brand']);
       return $this->single_photo($h_product['cover_image1']).'<br />'.$brand_name.'<br />'.$h_product['name'].'<BR>'.$h_product['cname'];
      
    } 
		
		function get_report_content($report_id){
			$dbh_r = $this->db_connect('read');
			
			$content_json = db_select_one($dbh_r, 'select content_json from product_reports where id=? and status > 0', $report_id);
			
			if($content_json == '')
				return '';
				
			$a_content = json_decode($content_json, true);
			
			$content_view = '';
			foreach ($a_content as $key => $value){
				//$content_view .= html_img('/'.$value['p'], '').'<br>';
				//$content_view .= html_img('/'.$value['p'], '/'.$value['p'], '', '100x100', array('openwin'	=> 1)).'<br>';
				$content_view .= html_img('/'.$value['p'], '/'.$value['p'], '', '250x250', array('openwin'	=> 1)).'<br>';
				$content_view .= $value['t'].'<br><br>';
			}
			
			return $content_view;
		}
		function get_report_category_scores($report_id, $product_id){
			//echo $report_id.'-'.$product_id;
			$dbh_r = $this->db_connect('read');
			
			$options = db_select_one($dbh_r, 'select vote_option from product where id=?', $product_id);
			
			$a_option = explode(',', $options);
			
			$a_field = array();
			for ($i=0; $i<count($a_option); $i++){
				$a_option[$i] = db_select_one($dbh_r, 'select cname from product_vote_option where id=?', $a_option[$i]);
				//$a_field[] = 'category_score'.$i+1;
			}
			//$fields = implode(',', $a_field);
			//echo $fields;
			//$a_score = db_selectrow_array($dbh_r,'select ? from product_reports where id=?', array($fields, $report_id));
			$a_score = db_selectrow_array($dbh_r,'select category_score1, category_score2, category_score3, category_score4, category_score5, category_score6, category_score7, category_score8 from product_reports where id=?', $report_id);
			
		
			$category_scores = '';
			for ($i=0; $i<count($a_option); $i++){
				$category_scores .= $a_option[$i].': '.$a_score[$i].'<br>';

			}
		
			//$category_scores = '';
			return $category_scores;
		}
    }
    
    ?>
